/* Descriptor sizes */
#define USB_DT_DEVICE_SIZE              18
#define USB_DT_HUB_SIZE					9
#define USB_DT_ENDPOINT_SIZE			7
#define USB_DT_INTERFACE_SIZE           9
#define USB_DT_CONFIG_SIZE              9


/* Descriptor types */
#define NO_DESCRIPTOR					0
#define USB_DT_DEVICE					0x01
#define USB_DT_CONFIGURATION			0x02
#define USB_DT_STRING					0x03
#define USB_DT_INTERFACE				0x04
#define USB_DT_ENDPOINT					0x05
#define USB_DT_DEVICEQUALIFIER			0x06
#define USB_DT_OTHER					0x07
#define USB_DT_INTERFACEPOWER			0x08
#define USB_DT_INTERFACEASSOCIATION		0x0B
#define USB_DT_HUB						0x29

#define USB_DIR_OUT					0
#define USB_DIR_IN					0x80		/* to host */

#define EINVAL		  22	/* Invalid argument */
#define EOPNOTSUPP	45	/* Operation not supported on transport endpoint */

#define USB_ENDPOINT_XFERTYPE_MASK	0x03		/* in bmAttributes */
#define USB_ENDPOINT_XFER_CONTROL	0
#define USB_ENDPOINT_XFER_ISOC		1
#define USB_ENDPOINT_XFER_BULK		2
#define USB_ENDPOINT_XFER_INT		3
#define USB_ENDPOINT_MAX_ADJUSTABLE	0x80

/* Classes */
#define USB_CLASS_PER_INTERFACE         0       /* for DeviceClass */
#define USB_CLASS_AUDIO                 1
#define USB_CLASS_COMM                  2
#define USB_CLASS_HID                   3
#define USB_CLASS_PHYSICAL              5
#define USB_CLASS_STILL_IMAGE           6
#define USB_CLASS_PRINTER               7
#define USB_CLASS_MASS_STORAGE          8
#define USB_CLASS_HUB                   9
#define USB_CLASS_CDC_DATA              0x0a
#define USB_CLASS_CSCID                 0x0b    /* chip+ smart card */
#define USB_CLASS_CONTENT_SEC           0x0d    /* content security */
#define USB_CLASS_VIDEO                 0x0e
#define USB_CLASS_WIRELESS_CONTROLLER   0xe0
#define USB_CLASS_MISC                  0xef
#define USB_CLASS_APP_SPEC              0xfe
#define USB_CLASS_VENDOR_SPEC           0xff

#define USB_CONFIG_ATT_ONE              (1 << 7)        /* must be set */
#define USB_CONFIG_ATT_SELFPOWER        (1 << 6)        /* self powered */
#define USB_CONFIG_ATT_WAKEUP           (1 << 5)        /* can wakeup */
#define USB_CONFIG_ATT_BATTERY          (1 << 4)        /* battery powered */



#define USB_REQ_GET_STATUS              0x00
#define USB_REQ_CLEAR_FEATURE           0x01
#define USB_REQ_SET_FEATURE             0x03
#define USB_REQ_SET_ADDRESS             0x05
#define USB_REQ_GET_DESCRIPTOR          0x06
#define USB_REQ_SET_DESCRIPTOR          0x07
#define USB_REQ_GET_CONFIGURATION       0x08
#define USB_REQ_SET_CONFIGURATION       0x09
#define USB_REQ_GET_INTERFACE           0x0A
#define USB_REQ_SET_INTERFACE           0x0B
#define USB_REQ_SYNCH_FRAME             0x0C

#define USB_TYPE_MASK                   (0x03 << 5)
#define USB_TYPE_STANDARD               (0x00 << 5)
#define USB_TYPE_CLASS                  (0x01 << 5)
#define USB_TYPE_VENDOR                 (0x02 << 5)
#define USB_TYPE_RESERVED               (0x03 << 5)

#define USB_RECIP_MASK                  0x1f
#define USB_RECIP_DEVICE                0x00
#define USB_RECIP_INTERFACE             0x01
#define USB_RECIP_ENDPOINT              0x02
#define USB_RECIP_OTHER                 0x03

#define DRIVER_VENDOR_NUM	0xaaaa		/* Atmel Corp */
#define DRIVER_PRODUCT_NUM	0xcccc		/* 4-Port Hub */
	
#define PORT_STAT_CONNECTION	0x0001
#define PORT_STAT_ENABLE		0x0002
#define PORT_STAT_RESET			0x0010
#define PORT_STAT_POWER			0x0100
#define PORT_STAT_LOW_SPEED		0x0200
#define PORT_STAT_HIGH_SPEED	0x0400
#define PORT_STAT_C_CONNECTION	0x0001
#define PORT_STAT_C_RESET		0x0010

#define USB_SPEED_LOW                    0
#define USB_SPEED_FULL                   1
#define USB_SPEED_HIGH                   2


#define REQUEST_STR(s) (           \
  s==USB_REQ_GET_STATUS?"GS":      \
  s==USB_REQ_CLEAR_FEATURE?"CF":   \
  s==USB_REQ_SET_FEATURE?"SF":	   \
  s==USB_REQ_SET_ADDRESS?"SA":     \
  s==USB_REQ_GET_DESCRIPTOR?"GD":  \
  s==USB_REQ_SET_DESCRIPTOR?"SD":  \
  s==USB_REQ_GET_CONFIGURATION?"GC": \
  s==USB_REQ_SET_CONFIGURATION?"SC": \
  s==USB_REQ_GET_INTERFACE?"GI":   \
  s==USB_REQ_SET_INTERFACE?"SI":   \
  s==USB_REQ_SYNCH_FRAME?"SY":     \
  "UNK")
  
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

